package it.tukano.fun;

/**
 * A function whose doApply method is called in the EDT. Notice that there is no
 * synchronization between the apply and the doApply call so the HB relationship
 * should be enforced somewhere else.
 * @author pgi
 * @param <IN> the type of the parameter of this function
 */
public abstract class EdtCallback1<IN> implements Function1<IN, Void> {

    /**
     * Instance initializer
     */
    public EdtCallback1() {
    }

    /**
     * Application runs the doApply method in the edt
     * @param p the argument passed to the doApply call
     * @return null
     */
    public Void apply(final IN p) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                doApply(p);
            }
        });
        return null;
    }

    /**
     * Subclasses implement this to define the task executed in the edt.
     * @param p the parameter received from the apply method.
     */
    protected abstract void doApply(IN p);
}
